<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/headeradmin.php");
?>

<section>
<hgroup>
<h1>Gebouw-detail deactiveren</h1>
</hgroup>
<?php 
    if (isset($_POST["bevestiging"]))
    {
        // Gets the name of the building spec that's going to be activated
        $getBuildingSpec = GetBuildingSpecById($_POST["id"]);
        while ($buildingspecRow = mysql_fetch_array($getBuildingSpec)){
            $name = $buildingspecRow['@buildingkey'];
        }
        
        // Activates the selected building 
        $resultUpdateBuildingSpecActivated = UpdateBuildingSpecActivated($_POST["id"], "F");
        if ($resultUpdateBuildingSpecActivated == 1)
        {
            echo ("<p>Gebouw-detail " .$name . " is gedeactiveerd<br>\n");
            echo ("<a href=\"gebouwdetailoverzicht.php?start=".$_POST['start']."\">Terug naar het overzicht van gebouw-details.</a></p>");
        }
    }
    else
    {
        // A check if the id is still a numeric character and hasn't been changed manually
        if (!is_numeric($_GET['id'])) { 
            header("Location: ".$cfg['basepath']."controller/gebouw/gebouw.php");
        }
        
        // Gets the data from the selected building spec
        $getBuildingSpec = GetBuildingSpecById($_GET["id"]);
        while ($buildingspecRow = mysql_fetch_array($getBuildingSpec)){
            echo "<p>Gebouw-detail = " . $buildingspecRow['@buildingkey'] . "<br>\n";
            echo "Commentaar = ". $buildingspecRow['@comment'] . "<br>\n";
        }
?>
<form action="<?php echo($_SERVER["PHP_SELF"]);?>" method="post">
    <p>
        <input type="hidden" name="bevestiging" value="1" />
        <input type="hidden" name="id" value="<?php echo($_GET["id"]);?>" />
        <input type="hidden" name="start" value="<?php if (isset($_GET['start'])){ echo $_GET['start']; } else { echo 0; }  ?>" />
        <input type="submit" value="Ja, deactiveren" />
        <input type="button" value="Nee, terug" onclick="javascript:history.back();" />
    </p>
</form>
<?php
    }
?>
</section>

<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/footer.php");
?>